<template>
  <div class="main-container">
    <div class="main-header">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item :to="{path: '/link/internalLink'}">站点内链管理</el-breadcrumb-item>
        <el-breadcrumb-item>新增内部链接</el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="wrap">
      <div class="content">
        <el-form class="mt-30" ref="form" :model="form" label-width="150px" style="width: 500px;">
          <el-form-item label="排序" prop="sort">
              <el-input-number v-model="form.sort" :min="0" :controls="false"></el-input-number>
            </el-form-item>
          <el-form-item label="锚文本" prop="anchorText" >
            <el-input v-model="form.anchorText"></el-input>
          </el-form-item>
            <el-form-item label="锚文本地址" prop="anchorUrl">
            <el-input v-model="form.anchorUrl" ></el-input>
          </el-form-item>
           <el-form-item label="是否支持文章内链" >
            <el-switch
              v-model="value"
              active-color="#409EFF"
              inactive-color="#C0CCDA">
            </el-switch>
          </el-form-item>
          <el-form-item label="内链位置" prop="anchorPosition">
            <el-input v-model="form.anchorPosition"></el-input>
          </el-form-item>
          <!-- <el-form-item label="联系方式" prop="contactWay">
            <el-input v-model="form.contactWay" ></el-input>
          </el-form-item>
          <el-form-item label="站点介绍" prop="introduce">
            <el-input v-model="form.introduce" type="textarea" ></el-input>
          </el-form-item> -->
          <el-form-item>
            <el-button type="primary" @click="onSubmit">保存</el-button>
            <el-button @click="onReset">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data () {
      return {
        value:false,
        form: {
          sort:'',
          anchorText: '',
          anchorUrl:'',
          anchorPosition:'',
          isArticleLink:''
        },
        courseList: [],
        currentPage: 1,
        pageSize:10,
        total:this.total,
        mdata: [],
        sort:''
      }
    },
    activated() {
      // this.loadData()
      this.form={
        sort:this.sort
      }
      console.log(this.$route)
      let sortNum = Number(this.$route.query.sort)
      this.form.sort = sortNum + 1
      this.sort = sortNum + 1
    },
    mounted() {
      this.form={
        sort:this.sort
      }
      console.log(this.$route)
      let sortNum = Number(this.$route.query.sort)
      this.form.sort = sortNum + 1
      this.sort = sortNum + 1
    },
    methods: {
      onSubmit() {
        if(this.value==true){
            this.form.isArticleLink=1
        }else{
            this.form.isArticleLink=0
        }
        this.$refs['form'].validate(valid => {
          if (valid) {
            const params = {
              ...this.form,
              // parentCode: this.parentCode,
              // courseLevel: 2,
              // documentType: 2
            }
            this.$api.internalLink.add(params).then(res => {
              if(res.success) {
                this.$message.success('保存成功')
                this.form.sort=this.sort
                this.form.anchorText=''
                this.form.anchorUrl=''
                this.form.anchorPosition=''
                this.form.isArticleLink=''
                this.$router.push('/link/internalLink');    
              }
            })
          }
        })
      },
      onReset() {
        this.$refs.form.resetFields()
        this.form.sort=this.sort
        this.form.anchorText=''
        this.form.anchorUrl=''
        this.form.anchorPosition=''
        this.form.isArticleLink=''
      }
    }
  }
</script>

<style>

 
</style>
